package cn.tedu.store.mapper;
/**
 * 用户信息测试类
 */
import java.util.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import cn.tedu.store.entity.User;

@RunWith(SpringRunner.class)
@SpringBootTest
public class UserMapperTestCase {

    @Autowired
    private UserMapper userMapper;
   
    //根据id 更新(上传)用户的头像
    @Test
   	public void updateAvatar() {
    	Integer uid = 9;
		String avatar = "upload/2019.jsp";
		String modifiedUser = "李白";
		Date modifiedTime = new Date();
		Integer rows = userMapper.updateAvatar(uid, avatar, modifiedUser, modifiedTime);
		System.err.println("rows=" + rows);
   	}
    
    //根据id 修改用户的用户名,手机号,邮箱资料,性别
    @Test
	public void updateInfo() {
    	User user = new User();
    	user.setId(9);
    	user.setGender(0);
    	user.setPhone("10010");
    	user.setEmail("12185690@qq.com");
    	user.setModifiedUser("小鲍");
    	Date now = new Date();
    	user.setModifiedTime(now);
		Integer rows = userMapper.updateInfo(user);
		System.err.println("rows=" + rows);
	}
    
    //修改密码
    @Test
	public void updatePassword() {
		Integer uid = 3;
		String password = "1234";
		String modifiedUser = "jungking";
		Date modifiedTime = new Date();
		Integer rows = userMapper.updatePassword(uid, password, modifiedUser, modifiedTime);
		System.err.println("rows=" + rows);
	}
    
    //根据id查询用户信息
    @Test
    public void findById() {
        Integer id = 3;
        User user = userMapper.findById(id);
        System.err.println(user);
    }
    
    //插入用户注册信息
    @Test
    public void addnew() {
    	Date now = new Date();
        User user = new User();
        user.setUsername("jungking");
        user.setPassword("1234");
        user.setGender(1);
        user.setPhone("10086");
        user.setEmail("root@tedu.cn");
        user.setSalt("Hello,MD5!");
        user.setIsDelete(0);
        user.setCreatedUser("Admin");
        user.setCreatedTime(now);
        user.setModifiedUser("Admin");
        user.setModifiedTime(now);
        Integer rows = userMapper.addnew(user);
        System.err.println(rows);
        System.out.println(user);
    }
    
    //根据用户名查询用户资料
    @Test
    public void findByUsername() {
        String username = "root";
        User user = userMapper.findByUsername(username);
        System.err.println(user);
    }

}